import 'dart:async';

import 'package:flutter/material.dart';
import 'package:myapp/ui/main_page.dart';
import 'package:myapp/util/image_utils.dart';

class SplashPage extends StatefulWidget {
  @override
  _SplashPageState createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
  Timer _timer;

  void _startMain() {
    Navigator.pushReplacement(
      context,
      MaterialPageRoute(builder: (BuildContext c) => MainPage()),
    );
  }

  @override
  void initState() {
    super.initState();
    _timer = Timer(Duration(seconds: 1), _startMain);
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      fit: StackFit.expand,
      children: [
        Image.asset(
          ImageUtils.wrapAssets("bg_splash"),
          fit: BoxFit.fill,
        )
      ],
    );
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    if (_timer != null) {
      _timer.cancel();
      _timer = null;
    }
  }
}
